Skip to content

Conversation

@dannykopping
Copy link
Collaborator

@dannykopping dannykopping commented Jan 17, 2026

TODO

Copy link
Collaborator Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@dannykopping dannykopping changed the title chore: refactoring for req dumps feat: inner agentic loop for openai responses requests (blocking only) Jan 17, 2026
pawbana and others added 3 commits January 19, 2026 09:31
…o bridge (#102)

The actions of determining whether to use Anthropic's streaming APIs and ensuring a uniform message payload format used to unmarshal and remarshal the same payload twice. This PR ensures we unmarshal once, do both, and then remarshal once.
@dannykopping dannykopping requested a review from pawbana January 19, 2026 12:14
@dannykopping dannykopping marked this pull request as ready for review January 19, 2026 12:14
i.reqPayload, err = sjson.SetBytes(i.reqPayload, "input", i.req.Input)
if err != nil {
i.logger.Error(ctx, "failure to marshal new input in inner agentic loop", slog.Error(err))
// TODO: what should be returned under this condition?
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs some discussion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think simply returning internal server error is ok.

@dannykopping dannykopping force-pushed the dk/mcp-responses-blocking branch from f6526ad to 101b739 Compare January 19, 2026 12:44
i.prepareRequestForAgenticLoop(response)
i.req.Input.OfInputItemList = append(i.req.Input.OfInputItemList, results...)

i.reqPayload, err = sjson.SetBytes(i.reqPayload, "input", i.req.Input)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm scared re-marshaling whole input array could cause re-encoding issues
sjson allows to append items to existing array by using -1 index value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, but unfortunately we'll need to remarshal at least some of the time since Input starts out as a single string (the prompt) and then changes to a list thanks for the fuckery of this API.

Gonna keep it as-is for now, but we may have to get clever later.

Added a note.

i.reqPayload, err = sjson.SetBytes(i.reqPayload, "input", i.req.Input)
if err != nil {
i.logger.Error(ctx, "failure to marshal new input in inner agentic loop", slog.Error(err))
// TODO: what should be returned under this condition?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think simply returning internal server error is ok.

"github.com/tidwall/sjson"
)

func (i *responsesInterceptionBase) injectTools() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be tested in base_test.go

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comment.


// prepareRequestForAgenticLoop prepares the request by setting the output of the given
// response as input to the next request, in order for the tool call result(s) to make function correctly.
func (i *BlockingResponsesInterceptor) prepareRequestForAgenticLoop(response *responses.Response) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be unit tested, also other functions added here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The integration tests already test these; coverage is pretty high.

Later we could add some unit tests here but I think coverage is pragmatic for now.

Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
@dannykopping dannykopping force-pushed the dk/mcp-responses-blocking branch from 101b739 to d44ad71 Compare January 19, 2026 16:45
@dannykopping dannykopping changed the base branch from dk/request-logging-redux to graphite-base/127 January 19, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants